<?php /*
	
*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
if(!isset($_SESSION['adminuserid']))
{
	header("location:index.php?msg=logfirst");
	die();
}

if(isset($_REQUEST['Submit']) && ($_REQUEST['Submit'])=="Send Mail")
{
	$news=$_REQUEST['newsletter'];
	$sqlsetting="select * from tblmystore";
	$ressetting=$obj_db->select($sqlsetting);
	if($ressetting) 
	{
		$from=stripslashes($ressetting[0]['varfromemail']);
	}
	
	$sql="select * from tblnewsletters where intid='$news'";
	$res = $obj_db->select($sql);
	if($res) {
		$sub= stripslashes($res[0]['varsubject']);
		$mess=stripslashes($res[0]['vartext']);
	}
	
	if(isset($_REQUEST['all']) && ($_REQUEST['all'])!="") {
		$sql12="select * from tblcustomers where intnewsletter='1'";
		$resman12 = $obj_db->select($sql12);
		if(count($resman12)>0)
		{
			for($m2=0;$m2<count($resman12);$m2++)
			{
				$custemail=$resman12[$m2]['varcustemail'];
				$mail_subject=$sub;				
				$message = "<html><head><title>".$sub."</title></head><body>".html_entity_decode(stripslashes($mess))."</body></html>";
				$headers  = 'MIME-Version: 1.0' . "\r\n";
				$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
				$headers .= 'From: '.$from. "\r\n";
				
				mail($custemail, $mail_subject, $message, $headers);
			}
		}
	} else {
		$email = $_REQUEST['custemail'];
		$mail_subject=$sub;
		$message = "<html><head><title>".$sub."</title></head><body>".html_entity_decode(stripslashes($mess))."</body></html>";
		$headers="From:".$from;
		$headers  = "MIME-Version: 1.0\r\n";
		$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
		mail($email, $mail_subject, $message, $headers);
	}
	header("location:sendnews.php?msg=newsent");
	die();
}



?>
<?php include("inc/header.php");?>
<body>
<script language="javascript" src="js/sendmail.js"></script>
<form name="sendmail" method="post" action="">
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" class="middlebackground">
  <tr>
    <td valign="top" align="center"><?php include(INC."top.inc.php");?></td>
  </tr>
  <tr valign="top">
    <td align="center">
	<table width="65%" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
      <tr>
        <td height="20" colspan="3" align="center" class="bg1"><strong>Send Newsletter...</strong></td>
        </tr>
      <tr>
        <td width="28%">&nbsp;</td>
        <td width="2%" align="right">&nbsp;</td>
        <td width="70%" align="right">(* All fields are Required)</td>
      </tr>
      <tr>
        <td align="right" class="sltimg"><input name="all" type="checkbox" id="all" value="1" /></td>
        <td align="center">&nbsp;</td>
        <td align="left">Send to All </td>
      </tr>
      <tr>
        <td align="right" class="sltimg">*Select User</td>

        <td align="center">:</td>
        <td align="left"><select name="customer" id="customer" onChange="this.form.submit();">
              <option value="0">Select Customer</option>
              <?php 
			  			$p_cust = $_REQUEST['customer'];
						$sql="select * from tblcustomers where intnewsletter='1'";
						$resman = $obj_db->select($sql);
						if(count($resman)>0)
						{
							for($m=0;$m<count($resman);$m++)
							{
			  ?>
              <option value="<?php echo stripslashes($resman[$m]['intcusid']);?>"<?php if($resman[$m]['intcusid'] == $p_cust){echo "selected";}?>>
                <?php echo stripslashes($resman[$m]['varcustfname']);					
							}
						}
					?>
              </option>
            </select>       </td>
      </tr>
      <tr>
        <td align="right" class="sltimg">&nbsp;</td>
        <td align="center">&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td align="right" class="sltimg">*E-Mail ID </td>
        <td align="center">:</td>
<?php 
	if(isset($_REQUEST['customer']) && ($_REQUEST['customer'])!="")	{ 
		$p_cust = mysql_real_escape_string($_REQUEST['customer']); 
	}
	$sql="select * from tblcustomers where intcusid='$p_cust'";
	$resman = $obj_db->select($sql);
	if(count($resman)>0)
	{
		for($m=0;$m<count($resman);$m++) {	?>
        <td align="left"><input name="custemail" type="text" id="custemail" value="<?php echo stripslashes($resman[$m]['varcustemail']);?>" size="26" /></td>
<?php
		}
	}
	
?>		
      </tr>
      <tr>
        <td align="right" class="sltimg">&nbsp;</td>
        <td align="center">&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td align="right" class="sltimg">*Newsletter</td>
        <td align="center" valign="top">:</td>
        <td align="left"><select name="newsletter" id="newsletter">
          <option value="0">Select Newsletter</option>
          <?php 
						$sql2="select * from tblnewsletters";
						$resman2 = $obj_db->select($sql2);
						if(count($resman2)>0) {
							for($m=0;$m<count($resman2);$m++) { ?>
          <option value="<?php echo stripslashes($resman2[$m]['intid']);?>"><?php echo stripslashes($resman2[$m]['varsubject']);?></option><?php					
							}
						}
					?>
        </select>
		</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td colspan="3" align="center"><input name="Submit" type="submit" class="btn" value="Send Mail" onClick="return check();"/>
          <input name="sendmail" type="hidden" id="sendmail" /></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td align="center"><?php include(INC."bottom.php");?></td>
  </tr>
</table>
</form>
</body>
</html>
